home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 2 / CU Amiga Magazine's Super CD-ROM 02 (1996)(EMAP Images)(GB)[!][issue 1996-04].iso / magazine / amiga_e / whatview / whatview.e < prev    next >
Text File  |  1994-05-02  |  27KB  |  724 lines

  1. /*******************************************************************************************/
  2. /* Source code generate by Gui2E v0.1 © 1994 NasGûl                                        */
  3. /*******************************************************************************************/
  4. /********************************************************************************
  5.  * << EUTILS HEADER >>
  6.  ********************************************************************************
  7.  ED               "EDG"
  8.  EC               "EC"
  9.  PREPRO           "EPP -t"
  10.  SOURCE           "WV.e"
  11.  EPPDEST          "WV_EPP.e"
  12.  EXEC             "WhatView"
  13.  ISOURCE          "WVPrefs.i"
  14.  HSOURCE          " "
  15.  ERROREC          " "
  16.  ERROREPP         " "
  17.  VERSION          "0"
  18.  REVISION         "12"
  19.  NAMEPRG          "WhatView"
  20.  NAMEAUTHOR       "NasGûl"
  21.  ********************************************************************************
  22.  * HISTORY :
  23.  *******************************************************************************/
  24.  
  25. OPT OSVERSION=37
  26.  
  27. MODULE 'intuition/intuition','gadtools','libraries/gadtools',
  28.        'intuition/gadgetclass','intuition/screens',
  29.        'graphics/text','exec/lists','exec/nodes',
  30.        'exec/ports','eropenlib','utility/tagitem',
  31.        'wvprefs','whatis','reqtools','libraries/reqtools',
  32.        'wb','utility','workbench/workbench','icon','rexxsyslib','workbench/startup',
  33.        'dos/dos','wbmessage','dos/dostags','dos/dosextens','dos/notify','dos/datetime',
  34.        'exec/libraries'
  35.  
  36. ENUM ER_NONE,ER_LOCKSCREEN,ER_VISUAL,ER_CONTEXT,ER_MENUS,ER_GADGET,ER_WINDOW,
  37.      ER_NOICON,ER_BADARGS,ER_PORT,ER_APPWIN,ER_NOPREFS,ER_APPITEM,ER_PORTEXIST,
  38.      ER_SIG
  39.  
  40. CONST WI_DEEP=$800000CB,WI_BUFFER=$800000CC,WI_BUFLEN=$800000CD
  41. ENUM ACT_WHATVIEW,ACT_INFO,ACT_ADDICON,ACT_EXECUTE
  42. CONST DEBUG=FALSE
  43. DEF screen:PTR TO screen,visual=NIL,tattr:PTR TO textattr,reelquit=FALSE,offy
  44. /****************************************
  45.  * wv Definitions
  46.  ****************************************/
  47. DEF wv_window=NIL:PTR TO window
  48. DEF wv_glist=NIL
  49. /* Gadgets */
  50. ENUM GA_G_WHATVIEW,GA_G_INFO,GA_G_ADDICON,GA_G_EXECUTE,GA_G_PREFS,GA_G_QUIT
  51. /* Gadgets labels of wv */
  52. DEF g_whatview,g_info,g_addicon,g_execute,g_prefs,g_quit
  53. /*********************************/
  54. /* Application def               */
  55. /*********************************/
  56. DEF myw=NIL:PTR TO wvbase
  57. DEF wvdisk:PTR TO diskobject
  58. DEF prgport=NIL:PTR TO mp
  59. DEF dummyport=NIL:PTR TO mp
  60. DEF publicport=NIL:PTR TO mp
  61. DEF appicon=NIL,appitem=NIL,appwindow=NIL,baselock
  62. DEF addicondir[256]:STRING,defprefsdir[256]:STRING,defaultdir[256]:STRING
  63. DEF wb_handle
  64. DEF nreqsig=-1
  65. DEF prgsig=NIL
  66. DEF nreq:PTR TO notifyrequest
  67. DEF maxarg=10
  68. DEF winx=10,winy=10
  69. PMODULE 'WVDATA'
  70. /*********************************/
  71. /* Message proc                  */
  72. /*********************************/
  73. PROC p_LookAllMessage() HANDLE /*"p_LookAllMessage()"*/
  74.     DEF sigreturn
  75.     DEF wvport:PTR TO mp
  76.     IF wv_window THEN wvport:=wv_window.userport ELSE wvport:=NIL
  77.     dWriteF(['p_LookAllMessage()\n'],0)
  78.     sigreturn:=Wait(Shl(1,wvport.sigbit) OR
  79.                     Shl(1,prgport.sigbit) OR Shl(1,nreqsig) OR Shl(1,publicport.sigbit) OR $F000)
  80.     IF (sigreturn AND Shl(1,wvport.sigbit))
  81.         IF p_LookwvMessage()=TRUE THEN p_CloseWindow()
  82.     ENDIF
  83.     IF (sigreturn AND Shl(1,prgport.sigbit))
  84.         p_LookAppMessage()
  85.         IF wv_window=NIL THEN Raise(p_OpenWindow())
  86.     ENDIF
  87.     IF (sigreturn AND Shl(1,nreqsig))
  88.         p_ReadPrefsFile('Env:Whatview.prefs')
  89.     ENDIF
  90.     IF (sigreturn AND Shl(1,publicport.sigbit))
  91.         p_LookPublicMessage()
  92.     ENDIF
  93.     IF (sigreturn AND $F000)
  94.         reelquit:=TRUE
  95.     ENDIF
  96.     Raise(ER_NONE)
  97. EXCEPT
  98.     RETURN exception
  99. ENDPROC
  100. PROC p_LookPublicMessage() /*"p_LookPublicMessage()"*/
  101.     DEF mymsg:PTR TO wvmsg
  102.     DEF stract[256]:STRING
  103.     DEF doit=-1
  104.     IF mymsg:=GetMsg(publicport)
  105.         StringF(stract,'\s',mymsg.name)
  106.         IF mymsg.lock=0
  107.             IF StrCmp(stract,'WHATVIEW',8) THEN doit:=ACT_WHATVIEW
  108.             IF StrCmp(stract,'INFO',4) THEN doit:=ACT_INFO
  109.             IF StrCmp(stract,'ADDICON',7) THEN doit:=ACT_ADDICON
  110.             IF StrCmp(stract,'EXECUTE',7) THEN doit:=ACT_EXECUTE
  111.             IF StrCmp(stract,'QUIT',4) THEN reelquit:=TRUE
  112.             IF StrCmp(stract,'FLUSH',5)
  113.                 p_FlushWhatis()
  114.                 JUMP allok
  115.             ENDIF
  116.             IF StrCmp(stract,'PREFS',5)
  117.                 p_CLIRun('WVprefs',defprefsdir,4000,0)
  118.                 JUMP allok
  119.             ENDIF
  120.         ENDIF
  121.         IF doit<>-1
  122.             IF p_EmptyList(myw.adremptylist)<>-1
  123.                 p_WriteFArgList(myw.adremptylist,doit)
  124.             ELSE
  125.                 IF p_WVFileRequester()
  126.                     p_WriteFArgList(myw.adremptylist,doit)
  127.                 ENDIF
  128.             ENDIF
  129.             p_RemoveArgList(myw.adremptylist,FALSE)
  130.             p_CleanArgActionList(myw.adractionlist)
  131.             JUMP allok
  132.         ELSE
  133.             p_AjouteArgNode(myw.adremptylist,mymsg.name,mymsg.lock)
  134.         ENDIF
  135.         allok:
  136.         ReplyMsg(mymsg)
  137.     ENDIF
  138. ENDPROC
  139. PROC p_LookAppMessage() HANDLE /*"p_LookAppMessage()"*/
  140. /********************************************************************************
  141.  * Para         : NONE
  142.  * Return       : NONE
  143.  * Description  : Parse Msg on App.
  144.  *******************************************************************************/
  145.     DEF appmsg:PTR TO appmessage
  146.     DEF b
  147.     DEF apparg:PTR TO wbarg
  148.     IF appmsg:=GetMsg(prgport)
  149.         apparg:=appmsg.arglist
  150.         FOR b:=0 TO appmsg.numargs-1
  151.             p_AjouteArgNode(myw.adremptylist,apparg[b].name,apparg[b].lock)
  152.         ENDFOR
  153.         ReplyMsg(appmsg)
  154.     ENDIF
  155.     Raise(ER_NONE)
  156. EXCEPT
  157.     RETURN exception
  158. ENDPROC
  159. PROC p_LookwvMessage() /*"p_LookwvMessage()"*/
  160.    DEF mes:PTR TO intuimessage
  161.    DEF g:PTR TO gadget
  162.    DEF type=0,infos=NIL,ret=FALSE
  163.    /*DEF pv[256]:STRING*/
  164.    WHILE (mes:=Gt_GetIMsg(wv_window.userport))
  165.    /*IF mes:=Gt_GetIMsg(wv_window.userport)*/
  166.        type:=mes.class
  167.        SELECT type
  168.            CASE IDCMP_MENUPICK
  169.               infos:=mes.code
  170.               SELECT infos
  171.               ENDSELECT
  172.            CASE IDCMP_CLOSEWINDOW
  173.               ret:=TRUE
  174.            CASE IDCMP_GADGETUP
  175.               g:=mes.iaddress
  176.               infos:=g.gadgetid
  177.               SELECT infos
  178.                   CASE GA_G_WHATVIEW
  179.                       ret:=TRUE
  180.                       IF p_EmptyList(myw.adremptylist)<>-1
  181.                           p_WriteFArgList(myw.adremptylist,ACT_WHATVIEW)
  182.                       ELSE
  183.                           IF p_WVFileRequester()
  184.                               p_WriteFArgList(myw.adremptylist,ACT_WHATVIEW)
  185.                           ENDIF
  186.                       ENDIF
  187.                       p_RemoveArgList(myw.adremptylist,FALSE)
  188.                       p_CleanArgActionList(myw.adractionlist)
  189.                   CASE GA_G_INFO
  190.                       ret:=TRUE
  191.                       IF p_EmptyList(myw.adremptylist)<>-1
  192.                           p_WriteFArgList(myw.adremptylist,ACT_INFO)
  193.                       ELSE
  194.                           IF p_WVFileRequester()
  195.                               p_WriteFArgList(myw.adremptylist,ACT_INFO)
  196.                           ENDIF
  197.                       ENDIF
  198.                       p_RemoveArgList(myw.adremptylist,FALSE)
  199.                       p_CleanArgActionList(myw.adractionlist)
  200.                   CASE GA_G_ADDICON
  201.                       ret:=TRUE
  202.                       IF p_EmptyList(myw.adremptylist)<>-1
  203.                           p_WriteFArgList(myw.adremptylist,ACT_ADDICON)
  204.                       ELSE
  205.                           IF p_WVFileRequester()
  206.                               p_WriteFArgList(myw.adremptylist,ACT_ADDICON)
  207.                           ENDIF
  208.                       ENDIF
  209.                       p_RemoveArgList(myw.adremptylist,FALSE)
  210.                       p_CleanArgActionList(myw.adractionlist)
  211.                   CASE GA_G_EXECUTE
  212.                       ret:=TRUE
  213.                       IF p_EmptyList(myw.adremptylist)<>-1
  214.                           p_WriteFArgList(myw.adremptylist,ACT_EXECUTE)
  215.                       ELSE
  216.                           IF p_WVFileRequester()
  217.                               p_WriteFArgList(myw.adremptylist,ACT_EXECUTE)
  218.                           ENDIF
  219.                       ENDIF
  220.                       p_RemoveArgList(myw.adremptylist,FALSE)
  221.                       p_CleanArgActionList(myw.adractionlist)
  222.                   CASE GA_G_PREFS
  223.                       ret:=TRUE
  224.                       p_CLIRun('WVprefs',defprefsdir,4000,0)
  225.                   CASE GA_G_QUIT
  226.                       ret:=TRUE
  227.                       reelquit:=TRUE
  228.               ENDSELECT
  229.        ENDSELECT
  230.        Gt_ReplyIMsg(mes)
  231.    ENDWHILE
  232.    /*ENDIF*/
  233.    WHILE (mes:=Gt_GetIMsg(wv_window.userport)) DO Gt_ReplyIMsg(mes)
  234.    RETURN ret
  235. ENDPROC
  236. /*********************************/
  237. /* Application proc              */
  238. /*********************************/
  239. PROC p_InitWVAPP() HANDLE /*"p_InitWVAPP()"*/
  240.     dWriteF(['p_InitWVAPP()\n'],0)
  241.     IF (prgsig:=AllocSignal(-1))=NIL THEN Raise(ER_SIG)
  242.     myw:=New(SIZEOF wvbase)
  243.     myw.adremptylist:=p_InitList()
  244.     myw.adractionlist:=p_InitList()
  245.     IF (prgport:=CreateMsgPort())=NIL THEN Raise(ER_PORT)
  246.     IF (dummyport:=CreateMsgPort())=NIL THEN Raise(ER_PORT)
  247.     IF (publicport:=p_CreatePublicPort('WhatViewPort',0))=NIL THEN Raise(ER_PORT)
  248.     p_InitPositionIcon(wvdisk)
  249.     IF (appitem:=AddAppMenuItemA(0,0,'WhatView',prgport,[MTYPE_APPMENUITEM,TAG_DONE]))=NIL THEN Raise(ER_APPITEM)
  250.     IF (appicon:=AddAppIconA(0,0,'WhatView',prgport,NIL,wvdisk,
  251.                              [MTYPE_APPICON,MTYPE_ICONPUT,wvdisk,TAG_DONE,0]))=NIL THEN Raise(ER_NOICON)
  252.     IF wvdisk THEN FreeDiskObject(wvdisk)
  253.     p_InitLockConfigFile()
  254.     Raise(ER_NONE)
  255. EXCEPT
  256.     RETURN exception
  257. ENDPROC
  258. PROC p_RemWVAPP() /*"p_RemWVAPP()"*/
  259.     dWriteF(['p_RemWVAPP()\n'],0)
  260.     p_RemLockConfigFile()
  261.     IF appicon THEN RemoveAppIcon(appicon)
  262.     IF appitem THEN RemoveAppMenuItem(appitem)
  263.     IF publicport THEN p_DeletePublicPort(publicport)
  264.     IF dummyport THEN DeleteMsgPort(dummyport)
  265.     IF prgport THEN DeleteMsgPort(prgport)
  266.     IF myw.adremptylist THEN p_RemoveArgList(myw.adremptylist,TRUE)
  267.     IF myw.adractionlist THEN p_RemoveActionList(myw.adractionlist,TRUE)
  268.     IF myw THEN Dispose(myw)
  269.     IF prgsig THEN FreeSignal(prgsig)
  270. ENDPROC
  271. PROC p_CreatePublicPort(name,priority) /*"p_CreatePublicPort(name,priority)"*/
  272. /********************************************************************************
  273.  * Para         : name (STRING),pri.
  274.  * Return       : address of the port if ok,else NIL
  275.  * Description  : Create a Public Message Port.
  276.  *******************************************************************************/
  277.     DEF p_node:PTR TO ln
  278.     DEF myport:PTR TO mp
  279.     dWriteF(['p_CreatePublicPort()\n'],0)
  280.     myport:=CreateMsgPort()
  281.     IF myport=0 THEN RETURN NIL
  282.     p_node:=myport.ln
  283.     p_node.name:=name
  284.     p_node.pri:=priority
  285.     p_node.type:=NT_MSGPORT
  286.     myport.flags:=PA_SIGNAL
  287.     AddPort(myport)
  288.     RETURN myport
  289. ENDPROC
  290. PROC p_DeletePublicPort(adr_port:PTR TO mp) /*"p_DeletePublicPort(adr_port)"*/
  291. /********************************************************************************
  292.  * Para         : Address of a public port.
  293.  * Return       : NONE
  294.  * Description  : Delete a public message port.
  295.  *******************************************************************************/
  296.     dWriteF(['p_DeletePublicPort()\n'],0)
  297.     IF adr_port THEN RemPort(adr_port)
  298.     IF adr_port THEN DeleteMsgPort(adr_port)
  299. ENDPROC
  300. PROC p_ReadPrefsFile(source) /*"p_ReadPrefsFile(source)"*/
  301.     DEF len,a,adr,buf,handle,flen=TRUE,pos
  302.     DEF chunk
  303.     DEF pv[256]:STRING
  304.     DEF node:PTR TO ln
  305.     DEF addact:PTR TO actionnode
  306.     DEF list:PTR TO lh,nn=NIL
  307.     dWriteF(['p_ReadPrefsFile()\n'],0)
  308.     IF (flen:=FileLength(source))=-1 THEN RETURN FALSE
  309.     IF (buf:=New(flen+1))=NIL THEN RETURN FALSE
  310.     IF (handle:=Open(source,1005))=NIL THEN RETURN FALSE
  311.     len:=Read(handle,buf,flen)
  312.     Close(handle)
  313.     IF len<1 THEN RETURN FALSE
  314.     adr:=buf
  315.     chunk:=Long(adr)
  316.     IF chunk<>ID_WVPR
  317.         Dispose(buf)
  318.         RETURN FALSE
  319.     ENDIF
  320.     p_RemoveActionList(myw.adractionlist,FALSE)
  321.     FOR a:=0 TO len-1
  322.         pos:=adr++
  323.         chunk:=Long(pos)
  324.         SELECT chunk
  325.             CASE ID_WVAC
  326.                 pos:=pos+4
  327.                 node:=New(SIZEOF ln)
  328.                 addact:=New(SIZEOF actionnode)
  329.                 addact.exectype:=Int(pos)
  330.                 addact.stack:=Long(pos+2)
  331.                 addact.priority:=Int(pos+6)
  332.                 StringF(pv,'\s',pos+8)
  333.                 node.name:=String(EstrLen(pv))
  334.                 node.succ:=0
  335.                 StrCopy(node.name,pv,ALL)
  336.                 pos:=pos+8+EstrLen(pv)+1
  337.                 StringF(pv,'\s',pos)
  338.                 addact.command:=String(EstrLen(pv))
  339.                 StrCopy(addact.command,pv,ALL)
  340.                 pos:=pos+EstrLen(pv)+1
  341.                 StringF(pv,'\s',pos)
  342.                 addact.currentdir:=String(EstrLen(pv))
  343.                 StrCopy(addact.currentdir,pv,ALL)
  344.                 pos:=pos+EstrLen(pv)+1
  345.                 CopyMem(node,addact.node,SIZEOF ln)
  346.                 AddTail(myw.adractionlist,addact.node)
  347.                 nn:=p_GetNumNode(myw.adractionlist,addact.node)
  348.                 IF nn=0
  349.                     list:=myw.adractionlist
  350.                     list.head:=addact.node
  351.                     node.pred:=0
  352.                 ENDIF
  353.                 addact.numarg:=0
  354.                 addact.cmd:=0
  355.                 IF node THEN Dispose(node)
  356.         ENDSELECT
  357.     ENDFOR
  358.     Dispose(buf)
  359.     RETURN TRUE
  360. ENDPROC
  361. PROC p_InitLockConfigFile() /*"p_InitLockConfigFile()"*/
  362.     dWriteF(['p_InitLockConfig()\n'],0)
  363.     nreq:=New(SIZEOF notifyrequest)
  364.     nreq.name:='Env:WhatView.prefs'
  365.     nreq.flags:=NRF_SEND_SIGNAL
  366.     nreq.port:=FindTask(0)
  367.     nreq.signalnum:=AllocSignal(nreqsig)
  368.     nreqsig:=nreq.signalnum
  369.     StartNotify(nreq)
  370. ENDPROC
  371. PROC p_RemLockConfigFile() /*"p_RemLockConfigFile()"*/
  372.     dWriteF(['p_RemLockConfig()\n'],0)
  373.     IF nreqsig THEN FreeSignal(nreqsig)
  374.     EndNotify(nreq)
  375. ENDPROC
  376. PROC p_StartCli() HANDLE /*"p_StartCli()"*/
  377. /********************************************************************************
  378.  * Para         : NONE
  379.  * Return       : ER_NONE if ok,else the error.
  380.  * Description  : Get .info and lock the currentdir.
  381.  *******************************************************************************/
  382.     DEF myargs:PTR TO LONG,rdargs=NIL
  383.     DEF prgname[256]:STRING
  384.     DEF pro:PTR TO process
  385.     dWriteF(['p_StartCli()\n'],0)
  386.     myargs:=[0]
  387.     IF rdargs:=ReadArgs('ICON',myargs,NIL)
  388.         IF myargs[0] THEN StrCopy(prgname,myargs[0],ALL) ELSE GetProgramName(prgname,256)
  389.         IF (wvdisk:=GetDiskObject(prgname))=NIL THEN Raise(ER_NOICON)
  390.         pro:=FindTask(0)
  391.         baselock:=CurrentDir(pro.currentdir)
  392.     ELSE
  393.         Raise(ER_BADARGS)
  394.     ENDIF
  395.     Raise(ER_NONE)
  396. EXCEPT
  397.     IF rdargs THEN FreeArgs(rdargs)
  398.     RETURN exception
  399. ENDPROC
  400. PROC p_StartWb() HANDLE /*"p_StartWb()"*/
  401. /********************************************************************************
  402.  * Para         : NONE
  403.  * Return       : ER_NONE if ok,else the error.
  404.  * Description  : Get .info and lock cureentdir.
  405.  *******************************************************************************/
  406.     DEF wb:PTR TO wbstartup
  407.     DEF args:PTR TO wbarg
  408.     DEF prgname[256]:STRING
  409.     dWriteF(['p_StartWb()\n'],0)
  410.     wb:=wbmessage
  411.     args:=wb.arglist
  412.     FindTask(0)
  413.     StrCopy(prgname,args[0].name,ALL)
  414.     baselock:=CurrentDir(args[0].lock)
  415.     IF (wvdisk:=GetDiskObject(prgname))=NIL THEN Raise(ER_NOICON)
  416.     Raise(ER_NONE)
  417. EXCEPT
  418.     RETURN exception
  419. ENDPROC
  420. PROC p_InitPositionIcon(s_d_o:PTR TO diskobject) /*"p_InitPositionIcon(s_d_o)"*/
  421. /********************************************************************************
  422.  * Para         : address of a diskobject structure
  423.  * Return       : NONE
  424.  * Description  : Look for POSX/POSY and DEFDIR (for icons) tooltypes.
  425.  *******************************************************************************/
  426.     DEF defdir[256]:STRING
  427.     DEF max
  428.     dWriteF(['p_InitPositionIcon()\n'],0)
  429.     s_d_o.currentx:=Val(FindToolType(s_d_o.tooltypes,'POSX'),NIL)
  430.     s_d_o.currenty:=Val(FindToolType(s_d_o.tooltypes,'POSY'),NIL)
  431.     IF defdir:=FindToolType(s_d_o.tooltypes,'DEFDIR')
  432.         IF defdir THEN StrCopy(addicondir,defdir,ALL)
  433.     ENDIF
  434.     IF defdir:=FindToolType(s_d_o.tooltypes,'DEFPREFSDIR')
  435.         IF defdir THEN StrCopy(defprefsdir,defdir,ALL)
  436.     ENDIF
  437.     IF max:=FindToolType(s_d_o.tooltypes,'MAXARG')
  438.         IF max THEN maxarg:=Val(max,NIL)
  439.         IF maxarg>20 THEN maxarg:=20
  440.     ENDIF
  441. ENDPROC
  442. PROC p_WBRun(com,dir,st,pr,num_arg,arg_list:PTR TO LONG) HANDLE /*"p_WBRun(com,di,st,pr,num_arg,arg_list)"*/
  443.     DEF execmsg:PTR TO mn
  444.     DEF wbsm:wbstartmsg
  445.     DEF rc=FALSE
  446.     DEF node:PTR TO ln
  447.     DEF oldcd
  448.     wbsm:=New(SIZEOF wbstartmsg)
  449.     execmsg:=wbsm
  450.     node:=execmsg
  451.     node.type:=NT_MESSAGE
  452.     node.pri:=0
  453.     execmsg.replyport:=dummyport
  454.     wbsm.name:=com
  455.     wbsm.dirlock:=Lock(dir,-2)
  456.     wbsm.stack:=st
  457.     wbsm.prio:=pr
  458.     wbsm.numargs:=num_arg
  459.     wbsm.arglist:=arg_list
  460.     oldcd:=CurrentDir(wbsm.dirlock)
  461.     Forbid()
  462.     IF wb_handle
  463.         PutMsg(wb_handle,wbsm)
  464.     ENDIF
  465.     Permit()
  466.     IF wb_handle
  467.         WaitPort(dummyport)
  468.         GetMsg(dummyport)
  469.         rc:=wbsm.stack
  470.     ENDIF
  471.     IF rc=0 THEN p_MakeWVRequest('WBRun Failed.','Ok',NIL)
  472.     Raise(ER_NONE)
  473. EXCEPT
  474.     CurrentDir(oldcd)
  475.     IF wbsm.dirlock THEN UnLock(wbsm.dirlock)
  476.     IF wbsm THEN Dispose(wbsm)
  477.     RETURN exception
  478. ENDPROC
  479. PROC p_CLIRun(cmd,dir,sta,pp) HANDLE /*"p_CLIRun(cmd,dir,sta,pp)"*/
  480.     DEF ofh:PTR TO filehandle
  481.     DEF ifh:PTR TO filehandle
  482.     DEF newct=NIL:PTR TO mp
  483.     DEF oldct:PTR TO mp
  484.     DEF oldcd
  485.     DEF newcd
  486.     IF ofh:=Open('NIL:',1006)
  487.         IF IsInteractive(ofh)
  488.             newct:=ofh.type
  489.             oldct:=SetConsoleTask(newct)
  490.             ifh:=Open('CONSOLE:',1005)
  491.             SetConsoleTask(oldct)
  492.         ELSE
  493.             ifh:=Open('NIL:',1005)
  494.         ENDIF
  495.     ENDIF
  496.     newcd:=Lock(dir,-2)
  497.     oldcd:=CurrentDir(newcd)
  498.     IF SystemTagList(cmd,[SYS_OUTPUT,NIL,
  499.                          SYS_INPUT,NIL,
  500.                          SYS_ASYNCH,TRUE,
  501.                          SYS_USERSHELL,TRUE,
  502.                          NP_STACKSIZE,sta,
  503.                          NP_PRIORITY,pp,
  504.                          NP_PATH,NIL,
  505.                          NP_CONSOLETASK,newct,
  506.                          0])
  507.     ENDIF
  508.     CurrentDir(oldcd)
  509.     IF newcd THEN UnLock(newcd)
  510.     IF ofh THEN Close(ofh)
  511.     IF ifh THEN Close(ifh)
  512.     Raise(ER_NONE)
  513. EXCEPT
  514.     RETURN exception
  515. ENDPROC
  516. PROC p_InitWBHandler() HANDLE /*"p_InitWBHandler()"*/
  517.     DEF ifh
  518.     DEF ofh
  519.     DEF wbh
  520.     dWriteF(['p_InitWBHandler()\n'],0)
  521.     IF (ifh:=Open('NIL:',1006))=NIL THEN Raise(NIL)
  522.     IF (ofh:=Open('NIL:',1005))=NIL THEN Raise(NIL)
  523.     SystemTagList('L:WBStart-Handler',[SYS_INPUT,ifh,
  524.                                       SYS_OUTPUT,ofh,
  525.                                       SYS_ASYNCH,TRUE,
  526.                                       SYS_USERSHELL,TRUE,
  527.                                       NP_CONSOLETASK,NIL,
  528.                                       NP_WINDOWPTR,NIL])
  529.     Delay(25)
  530.     wbh:=FindPort('WBStart-Handler Port')
  531.     Raise(wbh)
  532. EXCEPT
  533.     IF Not(wbh)
  534.         IF ifh THEN Close(ifh)
  535.         IF ofh THEN Close(ofh)
  536.     ENDIF
  537.     RETURN wbh
  538. ENDPROC
  539. PROC p_MakeWVRequest(bodytext,gadgettext,the_arg) /*"p_MakeWVRequest(bodytext,gadgettext,the_arg)"*/
  540. /********************************************************************************
  541.  * Para         : text (STRING), gadget (STRING), arg PTR TO LONG
  542.  * Return       : FALSE if cancel selected,else TRUE
  543.  * Description  : PopUp a Requester.
  544.  *******************************************************************************/
  545.     DEF ret
  546.     DEF taglist
  547.     IF wv_window<>NIL
  548.         taglist:=[RT_WINDOW,wv_window,RT_LOCKWINDOW,TRUE,RTEZ_REQTITLE,'WhatView v0.15 © NasGûl',RT_UNDERSCORE,"_",0]
  549.     ELSE
  550.         taglist:=[RTEZ_REQTITLE,'WhatView v0.15 © NasGûl',RT_UNDERSCORE,"_",0]
  551.     ENDIF
  552.     ret:=RtEZRequestA(bodytext,gadgettext,0,the_arg,taglist)
  553.     RETURN ret
  554. ENDPROC
  555. PROC p_MakeWVStringReq(t_reelname,t_idstr,t_size) /*"p_MakeWVStringReq(t_reelname,t_idstr,t_size)"*/
  556. /********************************************************************************
  557.  * Para         : reelname (STRING),id string (STRING) ,size (LONG)
  558.  * Return       : The result string of the request or NIL if cancel selected.
  559.  * Description  : PopUp a StringRequester to choose a command for a file.
  560.  *******************************************************************************/
  561.     DEF my_sreq:PTR TO rtfilerequester
  562.     DEF bodyreq[256]:STRING
  563.     DEF buffer[256]:STRING
  564.     DEF return_string[256]:STRING
  565.     DEF ret,taglist
  566.     StringF(bodyreq,'Execution d\aune commande pour:\nFichier :\s\nType    :\s\nSize    :\d',t_reelname,t_idstr,t_size)
  567.     StrCopy(buffer,'',ALL)
  568.     IF wv_window<>NIL
  569.         taglist:=[RT_WINDOW,wv_window,RT_LOCKWINDOW,TRUE,RTEZ_REQTITLE,'WhatView v0.15 © NasGûl',RTGS_GADFMT,'_Execute|_Cancel',RTGS_TEXTFMT,bodyreq,RT_UNDERSCORE,"_",0]
  570.     ELSE
  571.         taglist:=[RTEZ_REQTITLE,'WhatView v0.15 © NasGûl',RTGS_GADFMT,'_Execute|_Cancel',RTGS_TEXTFMT,bodyreq,RT_UNDERSCORE,"_",0]
  572.     ENDIF
  573.     IF my_sreq:=RtAllocRequestA(RT_REQINFO,NIL)
  574.         ret:=RtGetStringA(buffer,200,'WhatView v0.12',my_sreq,taglist)
  575.         IF ret
  576.             NOP
  577.         ELSE
  578.             buffer:=NIL
  579.         ENDIF
  580.         StringF(return_string,'\s',buffer)
  581.         IF my_sreq THEN RtFreeRequest(my_sreq)
  582.     ELSE
  583.         RETURN NIL
  584.     ENDIF
  585.     RETURN return_string
  586. ENDPROC
  587. PROC p_WVFileRequester() /*"p_WVFileRequester()"*/
  588. /********************************************************************************
  589.  * Para         : NONE
  590.  * Return       : FALSE if Cancel selected.
  591.  * Description  : PopUp a MultiFileRequester,Build the Wv_Arglist.
  592.  *******************************************************************************/
  593.     DEF reqfile:PTR TO rtfilerequester
  594.     DEF liste:PTR TO rtfilelist
  595.     DEF buffer[120]:STRING
  596.     DEF add_liste
  597.     DEF ret=TRUE
  598.     DEF the_reelname[256]:STRING
  599.     DEF lock
  600.     IF reqfile:=RtAllocRequestA(RT_FILEREQ,NIL)
  601.         buffer[0]:=0
  602.         RtChangeReqAttrA(reqfile,[RTFI_DIR,defaultdir])
  603.         add_liste:=RtFileRequestA(reqfile,buffer,'Whatview v0.15 © NasGûl',
  604.                                   [RTFI_FLAGS,FREQF_MULTISELECT,RTFI_OKTEXT,'_Whatview',RTFI_HEIGHT,200,
  605.                                    RT_UNDERSCORE,"_",TAG_DONE,0])
  606.         StrCopy(defaultdir,reqfile.dir,ALL)
  607.         IF reqfile THEN RtFreeRequest(reqfile)
  608.     ELSE
  609.         ret:=FALSE
  610.     ENDIF
  611.     liste:=add_liste
  612.     IF buffer[0]<>0
  613.         WHILE liste
  614.             StringF(the_reelname,'\s',liste.name)
  615.             IF lock:=Lock(defaultdir,-2)
  616.                 p_AjouteArgNode(myw.adremptylist,the_reelname,lock)
  617.                 UnLock(lock)
  618.             ENDIF
  619.             liste:=liste.next
  620.         ENDWHILE
  621.         IF add_liste THEN RtFreeFileList(add_liste)
  622.     ELSE
  623.         ret:=FALSE
  624.     ENDIF
  625.     RETURN ret
  626. ENDPROC
  627. PROC p_AddIcon(t_fullname,t_reelname,t_size,t_idstr) /*"p_AddIcon(t_fullname,t_reelname,t_lock,t_size,t_idstr)"*/
  628. /********************************************************************************
  629.  * Para         : fullname,reelname,id string,size.
  630.  * Return       : NONE
  631.  * Description  : Add a def icon to files or dirs.
  632.  *******************************************************************************/
  633.     DEF id_type
  634.     DEF id_icon[80]:STRING
  635.     DEF piv_str[256]:STRING
  636.     DEF fichier_source[256]:STRING
  637.     DEF fichier_destin[256]:STRING
  638.     DEF csdo:PTR TO diskobject
  639.     StrCopy(piv_str,addicondir,ALL)
  640.     id_type:=WhatIs(t_fullname,[WI_DEEP,1])
  641.     id_icon:=GetIconName(id_type)
  642.     AddPart(piv_str,id_icon,256)
  643.     StringF(fichier_source,'\s',piv_str)
  644.     IF id_icon<>NIL
  645.         StringF(fichier_destin,'\s',t_fullname)
  646.         csdo:=GetDiskObject(fichier_source)
  647.         IF csdo
  648.             PutDiskObject(fichier_destin,csdo)
  649.             IF csdo THEN FreeDiskObject(csdo)
  650.         ELSE
  651.             p_MakeWVRequest('Pas d\aicone par défaut pour:\nFichier :\s\nType    :\s\nSize    :\d','_Merci',[t_reelname,t_idstr,t_size])
  652.         ENDIF
  653.     ELSE
  654.         p_MakeWVRequest('Pas d\aicone par défaut pour:\nFichier :\s\nType    :\s\nSize    :\d','_Merci',[t_reelname,t_idstr,t_size])
  655.     ENDIF
  656. ENDPROC
  657. PROC p_FlushWhatis() /*"p_FlushWhatis()"*/
  658. /********************************************************************************
  659.  * Para         : NONE
  660.  * Return       : NONE
  661.  * Description  : Close/Open/Flush.
  662.  *******************************************************************************/
  663.     DEF library:PTR TO lib
  664.     IF whatisbase
  665.         library:=whatisbase
  666.         CloseLibrary(whatisbase)
  667.         IF library.opencnt>0
  668.             p_MakeWVRequest('Flush impossible \d programme(s)\nutilise(nt) la WhatIs.library','_Merci',[library.opencnt])
  669.         ELSE
  670.             p_MakeWVRequest('Flush de la WhatIs.library ok.','_Merci',NIL)
  671.         ENDIF
  672.         whatisbase:=OpenLibrary('whatis.library',3)
  673.     ENDIF
  674.     AskReparse($01)
  675. ENDPROC
  676. /*********************************/
  677. /* Main proc                     */
  678. /*********************************/
  679. PROC main() HANDLE /*"main()"*/
  680.     DEF testmain
  681.     tattr:=['topaz.font',8,0,0]:textattr
  682.     VOID '$VER:WhatView v0.15 © NasGûl (15/04/94)'
  683.     IF (testmain:=p_OpenLibraries())<>ER_NONE THEN Raise(testmain)
  684.     IF wbmessage<>NIL
  685.         IF (testmain:=p_StartWb())<>ER_NONE THEN Raise(testmain)
  686.     ELSE
  687.         IF (testmain:=p_StartCli())<>ER_NONE THEN Raise(testmain)
  688.     ENDIF
  689.     Forbid()
  690.     testmain:=FindPort('WhatViewPort') 
  691.     Permit()
  692.     IF testmain THEN Raise(ER_PORTEXIST)
  693.     Forbid()
  694.     wb_handle:=FindPort('WBStart-Handler Port')
  695.     Permit()
  696.     IF wb_handle=0 THEN wb_handle:=p_InitWBHandler()
  697.     IF (testmain:=p_InitWVAPP())<>ER_NONE THEN Raise(testmain)
  698.     IF p_ReadPrefsFile('Env:WhatView.prefs')=FALSE THEN Raise(ER_NOPREFS)
  699.     REPEAT
  700.         IF (testmain:=p_LookAllMessage())<>ER_NONE THEN Raise(testmain)
  701.     UNTIL reelquit=TRUE
  702.     Raise(ER_NONE)
  703. EXCEPT
  704.     IF myw THEN p_RemWVAPP()
  705.     CurrentDir(baselock)
  706.     p_CloseLibraries()
  707.     SELECT exception
  708.         CASE ER_LOCKSCREEN; WriteF('Lock Screen Failed.\n')
  709.         CASE ER_VISUAL;     WriteF('Error Visual.\n')
  710.         CASE ER_CONTEXT;    WriteF('Error Context.\n')
  711.         CASE ER_MENUS;      WriteF('Error Menus.\n')
  712.         CASE ER_GADGET;     WriteF('Error Gadget.\n')
  713.         CASE ER_WINDOW;     WriteF('Error Window.\n')
  714.         CASE ER_NOICON;     WriteF('no icon.\n')
  715.         CASE ER_BADARGS;    WriteF('Bad Args.\n')
  716.         CASE ER_NOPREFS;    WriteF('env:whatview.prefs ?\n')
  717.         CASE ER_APPWIN;     WriteF('Error AppWinidow.\n')
  718.         CASE ER_APPITEM;    WriteF('Error AppItem.\n')
  719.         CASE ER_PORT;       WriteF('Error Public port.\n')
  720.         CASE ER_PORTEXIST;  WriteF('WhatViewPort exist.\n')
  721.         CASE ER_SIG;        WriteF('Error Alloc signal.\n')
  722.     ENDSELECT
  723. ENDPROC
  724.